//
//  ActivityListViewController.m
//  UI-豆瓣项目APP
//
//  Created by liuxin on 15/9/8.
//  Copyright (c) 2015年 刘鑫. All rights reserved.
//
#import "ActivityListViewController.h"
#import "ActivityDetailViewController.h"
@interface ActivityListViewController ()
@property(nonatomic,copy)NSString*imageURL;
@end
@implementation ActivityListViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.allArray = [NSMutableArray array];
    
    NSString *urlStr = @"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php";
    [AppTools getLocalDataWithURL:urlStr andBlock:^(id dic) {
//        NSLog(@"%@",dic);
        NSMutableArray *array = [dic objectForKey:@"events"];
//        NSLog(@"array = %@",array);
        for (NSDictionary *dic in array) {
            Activitylist *activity = [[Activitylist alloc] init];
            [activity setValuesForKeysWithDictionary:dic];
            [self.allArray addObject:activity];
            [activity release];
        }
        [self.activityTableView reloadData];
        [self.hud hide:YES];
    }];
 
    self.navigationItem.title = @"活动";
    self.view.backgroundColor = [UIColor whiteColor];

    double height = ([[UIScreen mainScreen] bounds].size.height-65);
    self.activityTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375, height) style: UITableViewStylePlain];
    self.activityTableView.delegate =self;
    self.activityTableView.dataSource =self;
    [self.view addSubview:self.activityTableView];
        [_activityTableView release];
    
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.hud show:YES];
    self.hud.labelText = @"正在玩命加载中.....";
    self.hud.labelColor = [UIColor greenColor];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 186;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIndefider = @"cell";
    ActivityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndefider];
    if (cell == nil) {
        cell = [[ActivityListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndefider];
    }

    Activitylist *activity = [self.allArray objectAtIndex:indexPath.section];
//    NSLog(@"ac == %@",activity);
    cell.activity = activity;
    
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.allArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

//点击cell触发的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    Activitylist *activity = [self.allArray objectAtIndex:indexPath.section];
    ActivityDetailViewController *activityDetaileVC = [[ActivityDetailViewController alloc]init];
    activityDetaileVC.activityVC = activity;
    activityDetaileVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:activityDetaileVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end